﻿'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

''' <summary>
''' A Task is a well definied object which describes a specific behavior. While the behavior is
''' explicitly implemented in the Task, the actual execution is done from outside. Execution may
''' be synchrouns on the current thread, asynchronous using the ThreadPool or even synchronized
''' with a Dispatcher.
''' </summary>
Public Interface ITask
    ''' <summary>
    ''' Gets an unique identifier of the task.
    ''' </summary>
    ReadOnly Property Id() As Guid

    ''' <summary>
    ''' Gets a value indicating whether the task execution completed.
    ''' </summary>
    ''' <remarks>IsCompleted is also true when an error occurs during execution.</remarks>
    ReadOnly Property IsCompleted() As Boolean

    ''' <summary>
    ''' Gets a value indicating whether the Run method is blocking the current
    ''' thread until execution completes.
    ''' </summary>
    ReadOnly Property IsAsync() As Boolean

    'ReadOnly Property IsAutoComplete() As Boolean

    ''' <summary>
    ''' The Completed event is risen when the task has completed.
    ''' </summary>
    Event Completed As EventHandler

    ''' <summary>
    ''' Runs the task logic.
    ''' </summary>
    ''' <remarks>This method can either be implemented synchronous, so it will
    ''' block the current thread until the task execution completes or asynchronus.</remarks>
    Sub Run()

    ''' <summary>
    ''' Blocks the current thread until the task execution completes.
    ''' </summary>
    Sub WaitCompleted()
End Interface